package net.gdface.cassdk;

import net.gdface.sdk.fse.BaseFeatureSearchEngine;
import net.gdface.sdk.fse.FeatureSe;

/**
 * 基于CASSDK算法的特征码内存搜索引擎(FSE,feature search engine)java接口类(JNI)
 * @author guyadong
 *
 */
public class FseBridge extends BaseFeatureSearchEngine{
	private static final String DEFAULT_LIB_NAME="fse_cas_jni";
	protected static final String FSE_HOME = getFseHome();
	private static final String LIB_NAME = null == FSE_LIBNAME ? DEFAULT_LIB_NAME  :  FSE_LIBNAME;
	private static final FeatureSe FSE_INSTANCE = new FeatureSeImpl(FseBridge.class.getName());
	static {
		String fsebin = null == FSE_HOME ? null : FSE_HOME + "/bin";
		try{
			//loadLibrary(fsebin,"fse_cas");
			loadLibrary(fsebin,LIB_NAME);
			init();
			libraryLoaded = true;
		}catch(UnsatisfiedLinkError e){
			if(null == FSE_HOME){
				throw new UnsatisfiedLinkError(String.format("%s,\nplease set environment variable '{}' "
						+ "to define install location of feature_se ,retry again",
						e.getMessage(),ENV_FSE));
			}
			throw e;
		}
	}
	protected FseBridge() {
	}
	
	public static FeatureSe getFeatureSe(){
		return isLibraryLoaded() ? FSE_INSTANCE : null;
	}
}
